/**
 * 
 */
package com.orange.modules.dao.expert;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.orange.dbhelp.DbHelper;
import com.orange.dbhelp.page.Page;
import com.orange.modules.entity.expert.AuthExam;
import com.orange.modules.entity.expert.AuthSpecialTask;

/**
 * @author gaogs
 *
 * 2016-11-30
 */
@Repository
public class AuthSpecialTaskRepository {
	
	@Resource(name = "dbHelper")
	private DbHelper dbHelper;
	
	@Autowired
	private AuthSpecialTaskDao authSpecialTaskDao;
	
	/**
	 * 保存专业技能信息
	 * @param a
	 */
	public void saveAuthSpecialTaskInfo(AuthSpecialTask a){
		authSpecialTaskDao.save(a);
	}
	
	/**
	 * 删除专业技能
	 * @param pid
	 */
	public void deleteAuthSpecialTaskInfo(String pid){
		authSpecialTaskDao.delete(pid);
	}
	
	/**
	 * 根据id查询专业技能任务信息
	 * @param pid
	 * @return
	 */
	public AuthSpecialTask queryAuthSpecialTaskInfoById(String pid){
		AuthSpecialTask a=authSpecialTaskDao.findOne(pid);
		return a;
	}
	
	/**
	 * 分页查询试题
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	public Page<AuthSpecialTask> queryauthSpecialTaskPage(Map<String, String> map) throws SQLException {
		StringBuilder sql = new StringBuilder("SELECT TOP 1000  aa.p_id as pid ,aa.s_name as name ,aa.s_type as type ,aa.s_major as major ," +
				" aa.s_word_name as wordName ,aa.s_word_url as wordUrl ,aa.s_create_time as createTime,aa.s_remark as remark " +
				" FROM t_auth_special_task as aa WHERE 1=1 ");
		
		if (StringUtils.isNotBlank(map.get("name"))) {
			sql.append(" AND aa.s_name like '%" + map.get("name")+ "%'");
		}
		if (StringUtils.isNotBlank(map.get("type"))) {
			sql.append(" AND aa.s_type ='" + map.get("type")+ "'");
		}
		
		sql.append(" ORDER BY aa.s_create_time DESC ");
		Page<AuthSpecialTask> authSpecialTask = dbHelper.getPage(sql.toString(),AuthSpecialTask.class, Integer.valueOf(map.get("pageNumber")),
				Integer.valueOf(map.get("pageSize")), new Object[] {});
		return authSpecialTask;
	}
	
	/**
	 * 联络员分工-查询所有专业技能和其他任务
	 * @return
	 * @throws SQLException 
	 */
	public List<AuthSpecialTask> queryAuthSpecialTaskinfoss() throws SQLException{
		String sql="SELECT TOP 1000 aa.p_id as pid ,aa.s_name as name ,aa.s_type as type ," +
				" aa.s_word_name as wordName ,aa.s_word_url as wordUrl  ,aa.s_create_time as createTime," +
				" aa.s_remark as remark " +
				" FROM t_auth_special_task as aa  ORDER BY aa.s_type ASC ";
		List<AuthSpecialTask> list=dbHelper.getBeanList(sql, AuthSpecialTask.class);
		return list;
	}
	
	/**
	 * 根据专业技能类型查询专业技能
	 * @return
	 * @throws SQLException 
	 */
	public List<AuthSpecialTask> queryAuthSpecialTaskByType(String type, String major) throws SQLException{
		String sql="SELECT aa.p_id as pid ,aa.s_name as name ,aa.s_type as type ," +
				" aa.s_word_name as wordName ,aa.s_word_url as wordUrl ," +
				" aa.s_create_time as createTime ,aa.s_remark as remark, aa.s_state as state" +
				" FROM t_auth_special_task as aa  WHERE aa.s_type=? and aa.s_major = ?";
		List<AuthSpecialTask> list=dbHelper.getBeanList(sql, AuthSpecialTask.class,type,major);
		return list;
	}
	
	/**
	 * 查询taskId
	 * @throws SQLException 
	 */
	public List<AuthSpecialTask> queryTaskNameByType(String major) throws SQLException{
		String sql = "SELECT TOP 1000 aa.p_id as pid, aa.s_name as name FROM t_auth_special_task as aa WHERE aa.s_major = ?";
		List<AuthSpecialTask> list = dbHelper.getBeanList(sql, AuthSpecialTask.class, major);
		return list;
		
	}
	

}
